home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / FORTH / DRAW_FOL / ABOUT_DR.AWE
Text File  |  1992-05-17  |  4KB  |  81 lines

  1. Class Drawer is one way to support a window with scrollable contents.
  2. There are many ways to do this, each with its advantages and disadvantages.
  3. This technique will not be apropriate for all situations, but it was easy
  4. to implement and is very general.
  5.  
  6. Also needed are the two supplied, and modified, files for the View and
  7. Scroller classes.  The View class was only slightly modified in that the
  8. vscroll? and hscroll? instance variables were promoted from the Scroller
  9. subclass to the View superclass.  And the SetupDraw: method was modified.
  10.  
  11. The Scroller class and supporting Vscroll/Hscroll classes were fairly
  12. heavily modified.
  13.  
  14.  
  15. The idea is to provide a general technique for scrolling the contents of
  16. a window when the contents is too big to fit.  This will work for resizable
  17. windows as well.
  18.  
  19.  
  20. A brief explanation of the overall logic is as follows.
  21.  
  22. The view and scroller classes are set up basically as before, except the 
  23. ACTIONS x-arrays of the scrollbars are loaded with CFAs that reference the 
  24. value thisCtl.  ThisCtl, of course, will contain the current control object 
  25. (the one hit by the mouse), and from that control object will be known the 
  26. owning view object, since ^MYVIEW is an ivar of a control.  
  27.  
  28. A new instance variable of class Scroller is DrawObject, which will contain
  29. a Drawer object which must be passed upon Scroller instantiation.  The Drawer
  30. object must respond appropriately to a few messages.  Note that late-binding
  31. (or should I be calling it dynamic binding?) is heavily used throughout.
  32. Anyway, since the key to drawing in a scrollable window is usually just drawing
  33. relative to the control values, we pass the Scroller object itself to the
  34. Drawer object when making a request for the Drawer object to draw itself.
  35. See the sdraw: method in class Drawer.  The scroller object will contain all
  36. of the information we need to efficiently (or inefficiently) do our drawing.
  37. Since the View subclass (which is what a Scroller is) will properly clip
  38. the drawing, we can simply look at the control values and draw relative to
  39. them.  It will be more efficient, but certainly more complex, to also inspect
  40. the size of the viewrect as well and limit drawing appropriately.
  41.  
  42. Class Drawer by itself will not do anything.  It is intended to be subclassed, 
  43. and class DemoDrawer is an example.  All that is really needed in a Drawer is a 
  44. proper response to the (late-bound) message reldraw: (relative draw), which 
  45. also passes the x and y location from which to base all drawing.  
  46.  
  47. Note that a Drawer must contain other pertinent information needed for scrolling
  48. such as the overall pixel size of the Drawer and how many pixels to scroll for
  49. any given control hit situation.  Defaults are provided, but these should be
  50. set as needed.
  51.  
  52. DEMO
  53.  
  54. See the end of the file Drawer for an example of how to use a Drawer.
  55. Try resizing the demo window.  Note that the scrollbars will appropriately
  56. activate and deactivate when the window is resized.
  57.  
  58. CAVEATS
  59.  
  60. This code hasn't really been thoroughly tested, but it may prove useful
  61. as a starting point for more robust scrolling views.
  62.  
  63. This Scroller class is really not intended to be able to contain subviews.
  64. For that matter, I'm not even sure that it will work as a subview, although
  65. it probably should.
  66.  
  67. Also, both horizontal and vertical scrollbars are required.  This could be
  68. changed so that only one or the other is needed.
  69.  
  70. Since the control ranges and values are the actual pixel extents and offsets
  71. of the Drawer, we are somewhat limited in drawing size.  Another approach
  72. might be to have the control range correspond to, for example, the number of
  73. "cells" to be drawn where each cell could represent many pixels.
  74.  
  75. Also, another approach might simply offset the coordinate system itself based
  76. on the control values.
  77.  
  78. Feedback/comments are welcome.
  79.  
  80. Doug Hoffman  Compuserve 72310,1743
  81. 5/17/92